import projectSetting from '@/settings/projectSetting.js'
import dokey from '@/utils/dokey.js'
import store from '@/store'
export const uploadFile = (url, tempFilePaths, data = {}) => {
  return new Promise((resolve, reject) => {
    return uni.uploadFile({
      url: projectSetting.appApiUrl + url,
      filePath: tempFilePaths,
      name: 'file',
      header: {
        'Is-Axios': 1,
        'E-DEVICE-TYPE': projectSetting.appDeviceType,
        'E-APP-ID': projectSetting.appId,
        'E-MHM-ID': store.state.projectSetting.globSchoolId,
        'E-SHARE-CODE': store.state.projectSetting.globShareCode,
        'E-USER-AK': store.getters['user/getToken'].ak,
        'E-USER-SK': store.getters['user/getToken'].sk,
        ...dokey.secretdate(data),
      },
      formData: data,
      success: (succ) => {
        const res = JSON.parse(succ.data)
        if (res.code == 1) {
          resolve(res)
        } else {
          reject(res)
        }
      },
    })
  })
}
